

from sketchc import *
from numpy import linspace

window = Window2((1000, 800))


wheel6 = Wheelp(V2(-2, -2), 0.5, color=(255, 0, 0))
@wheel6.set_callback
def _(delta):
    x, y =delta
    box1.t.walk(rot = vrot(U3(0, 0, 1), x))
    box1.t.walk(rot = vrot(U3(-1, 0, 0), y))
wheel6 >> window

wheel4 = Wheelh(V2(-2, -1.3), color=(255, 0, 0))
@wheel4.set_callback
def _(delta):
    box1.t.walk(rot=vrot(U3(0, 1, 0), delta))
wheel4 >> window



def f2(angle1):
    r1 = 2
    r2 = 1
    d = U3(cos(angle1), sin(angle1), 0)
    p = d * r1
    return p

tox = Obj()
tail1 = Tail(f2(-0.01), f2(0))
n = 50
tail1.l6 = [U3(0.95 * cos(pi * 2 / n * i), 0, 0.95 * sin(pi * 2 / n * i)) for i in range(n)][::-1]
for t in linspace(0, 1.1, 50):
    tail1.push(f2(t * tau))
tox.vertices = tail1.acc[0] + tail1.now[0]
tox.normals = tail1.acc[1] + tail1.now[1]
tox.vertices = [p / 5 for p in tox.vertices]
# ~ box1 = make_block(U3(1, 1, 1))
box1 = tox
box1.prog = prog2
box1.u(window.ctx)  # .u()是更新vao用的，vao又绑定于context
box1.color = V3(1.0, 1.0, 1.0)

box1 >> window



camera = Camera(U3(0, -3, 1))
camera >> window        # 识别为camera则自动作为主camera

clock = pygame.time.Clock()
while True:
    dt = clock.tick(60)
    # ~ window.update(dt)
    for e in pygame.event.get():
        if e.type == pygame.QUIT:
            exit()
        window.dispatch(e)
    window.render()   # screen 操作需要写在window的槽里
    pygame.display.flip()


